package top.ahwyy.controller.Action;

import java.io.UnsupportedEncodingException;
import java.util.ArrayList;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.ServletResponseAware;

import top.ahwyy.controller.impl.cardImpl;
import top.ahwyy.controller.impl.userImpl;
import top.ahwyy.controller.inter.card;
import top.ahwyy.controller.inter.user;
import top.ahwyy.model.zanUserdata;
import top.ahwyy.utils.filterSpecialChar;


public class openCardAction implements ServletRequestAware,ServletResponseAware{

	HttpServletRequest request = null;
	HttpServletResponse response = null;
	public String forumId;
	
	
	public String execute(){
		//System.out.println(forumId);
		response.setContentType("text/html;charset=utf-8");
		try {
			request.setCharacterEncoding("utf-8");
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		if(forumId == null || forumId.equals(""))
			return "false";
		int fid = new Integer(forumId);
		user ui = new userImpl();
		card ci = new cardImpl();
		int uid = ui.getUserIdByForumId(fid);
		int danqianUid = ci.getUserIdByUn(request.getSession().getAttribute("un").toString());
		
		
		String ulogo = ui.getUserLogoByUserId(uid);
		String un = ui.getUserNameByUserId(uid);
		String lastUpdateTime = ci.getLastUpdateTimeByForumId(fid);
		String content = filterSpecialChar.filterSpecialChar2(ci.getContentByForumId(fid));
		
		request.setAttribute("ulogo", ulogo);
		request.setAttribute("un2", un);
		request.setAttribute("lastUpdateTime", lastUpdateTime);
		request.setAttribute("content", content);
		request.setAttribute("danqianUid", danqianUid);
		request.setAttribute("forumId", fid);
		
		ArrayList<zanUserdata> al = new ArrayList<zanUserdata>();
		al = ci.getZanUserList(fid);
		request.setAttribute("zanUserdataList", al);
		request.setAttribute("userZan", fid+" "+danqianUid);
		
		
		
		
		
		return "success";
	}
	
	@Override
	public void setServletResponse(HttpServletResponse arg0) {
		// TODO Auto-generated method stub
		this.response = arg0;
		
	}

	@Override
	public void setServletRequest(HttpServletRequest arg0) {
		// TODO Auto-generated method stub
		this.request = arg0;
	}

}
